home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / BORL_TIP / TI1000 / TI1761.ASC < prev    next >
Text File  |  1994-01-10  |  4KB  |  199 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Pascal                                NUMBER  :  1761
  9.   VERSION  :  6.0 & up
  10.        OS  :  DOS
  11.      DATE  :  January 10, 1994                         PAGE  :  1/3
  12.  
  13.     TITLE  :  How to read an enhanced keyboard
  14.  
  15.  
  16.  
  17.  
  18.   {
  19.   The code included in this example shows how to read
  20.   an enhanced keyboard using Turbo Pascal. That is, it detects
  21.   if the F11, F12, etc keys are pressed. It provides a substitute
  22.   for the ReadKey and KeyPressed functions.
  23.        This TI includes two source files, the first a unit
  24.   called ENHKEY.PAS and the second a test program called TEST.PAS.
  25.   ENHKEY.PAS contains three routines:
  26.  
  27.      KeyEPressed: Works just like the CRT routine called
  28.   KeyPressed,
  29.             except it detects keypresses on enhanced keys.
  30.  
  31.      NewReadKey:  Works very much like ReadKey, except it detects
  32.             enhanced keys.
  33.  
  34.      ReadEKey:    This is the raw readkey function. It returns a
  35.   word.
  36.             The high order word contains the scan code and the
  37.             low word contains the regular key. Some users might
  38.             not want to call this function directle, but instead
  39.             might want to access it through the NewReadKey
  40.   function,
  41.             which acts much more like the original ReadKey function
  42.             from the CRT unit.
  43.  
  44.        The code in the EnhKey unit depends on interrupt 16h,
  45.   functions
  46.   10 and 11, both of which assume the presence of AT or better
  47.   computer.
  48.   In this day and age, that's a fairly safe bet, but you should be
  49.   aware
  50.   that this code will not run on an old XT.
  51.        Notice that if NewReadKey returns zero the first time it is
  52.   called, you can grab the scan code in the global variable
  53.   ScanCode,
  54.   or you can call NewReadKey a second time to return the ScanCode.
  55.   }
  56.  
  57.   unit EnhKey;
  58.  
  59.   interface
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Pascal                                NUMBER  :  1761
  75.   VERSION  :  6.0 & up
  76.        OS  :  DOS
  77.      DATE  :  January 10, 1994                         PAGE  :  2/3
  78.  
  79.     TITLE  :  How to read an enhanced keyboard
  80.  
  81.  
  82.  
  83.  
  84.   var
  85.     ScanCode: Byte;
  86.  
  87.   function KeyEPressed: Boolean;
  88.   function ReadEKey: Word;
  89.   function NewReadKey: Char;
  90.  
  91.   implementation
  92.  
  93.   function KeyEPressed: Boolean; assembler;
  94.   asm
  95.     mov ah, $11
  96.     int 16h
  97.     mov ax, 1
  98.     jnz @@True
  99.     xor ax, ax
  100.   @@True:
  101.   end;
  102.  
  103.   function ReadEKey: Word; assembler;
  104.   asm
  105.     mov ah, 10h
  106.     int 16h
  107.   end;
  108.  
  109.   function NewReadKey: Char;
  110.   var
  111.     Ch: Word;
  112.   begin
  113.     if ScanCode <> 0 then begin
  114.       NewReadKey := Char(ScanCode);
  115.       ScanCode := 0;
  116.       exit;
  117.     end;
  118.     Ch := ReadEKey;
  119.     if Lo(Ch) = 0 then begin
  120.       ScanCode := Hi(Ch);
  121.       NewReadKey := #0;
  122.       exit;
  123.     end;
  124.     NewReadKey := Char(Lo(Ch));
  125.   end;
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Pascal                                NUMBER  :  1761
  141.   VERSION  :  6.0 & up
  142.        OS  :  DOS
  143.      DATE  :  January 10, 1994                         PAGE  :  3/3
  144.  
  145.     TITLE  :  How to read an enhanced keyboard
  146.  
  147.  
  148.  
  149.  
  150.   begin
  151.     ScanCode := 0;
  152.   end.
  153.   begin
  154.     ScanCode := 0;
  155.   end.
  156.  
  157.   { ================= The Test Program ================ }
  158.  
  159.   program Test;
  160.   uses
  161.     EnhKey;
  162.  
  163.   var
  164.     Ch: Char;
  165.     i: Integer;
  166.   begin
  167.     i := 0;
  168.     while (Ch <> #27) do begin
  169.       if KeyEpressed then begin
  170.         Ch := NewReadKey;
  171.         if Ch = #0 then begin
  172.        Ch := NewReadKey;
  173.        WriteLn('Enhanced: ', Ch)
  174.         end else
  175.        WriteLn('Normal: ', Ch);
  176.         inc(i);
  177.       end;
  178.     end;
  179.   end.
  180.  
  181.   DISCLAIMER: You have the right to use this technical information
  182.   subject to the terms of the No-Nonsense License Statement that
  183.   you received with the Borland product to which this information
  184.   pertains.
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.